//
//  ShrinkTreeViewController.h
//  MClient
//
//  Created by cuiyuguo on 11-2-19.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "Three20/Three20.h"

static NSString *const shrinkTreeDB_NodeId   = @"nodeId";
static NSString *const shrinkTreeDB_FatherId = @"fatherId";
static NSString *const shrinkTreeDB_NodeName = @"nodeName";
static NSString *const shrinkTreeDB_NodeData = @"nodeData";
static NSString *const shrinkTreeDB_NodeDataLen = @"nodeDataLen";
static NSString *const shrinkTreeDB_hasChild = @"hasChild";

@interface ShrinkTreeDataBase : NSObject {
	sqlite3*    _database;
	BOOL        _isOpened;
	char*       _sqlBuf;
	NSString*   _tableName;
}
- (id)initWithDatabaseName:(NSString*)name withTableName:(NSString*)tableName;

- (BOOL) insertTreeNode:(NSDictionary*)node withFatherId:(NSString*)fatherId;
- (NSMutableDictionary*) getTreeNodeData:(NSString*)nodeId withTag:(BOOL)isGetNodeData;
- (NSArray*) getTreeNodeDatas:(NSString*)fatherId withTag:(BOOL)isGetNodeData;
- (BOOL) truncateTable;
- (BOOL) childNodesExist:(NSString*)nodeId;
- (BOOL) updateTreeNodeData:(NSDictionary*)node withNodeId:(NSString*)nodeId;

@property(nonatomic, assign)BOOL        isOpened;
@property(nonatomic, retain)NSString*   tableName;
@end

@interface MCTabStrip : TTTabStrip {
}
@end

@interface ShrinkTreeViewController : MCViewController<TTTabDelegate, UITextFieldDelegate> {
	NSMutableDictionary *treeData;
	NSMutableArray *treeNodes;
	NSMutableDictionary *treeNodePosition;
	NSString*              fatherId;
	NSString*              strSelectedIndex;
	NSMutableArray*        curArray;
	NSMutableArray*        selectedArray;
	MCTabStrip*            tabBarHeader;
	CGFloat                TTTabGridHeight;
	TTTabGrid*             tabBarTreeNodes;
	UIScrollView*          scrollView;
	ShrinkTreeDataBase*    shrinkTreeDataBase;
	NSMutableArray*        treeNodesItemBack;
}

@property (nonatomic, retain) NSMutableDictionary *treeData;
@property (nonatomic, retain) NSMutableArray *treeNodes;
@property (nonatomic, retain) NSMutableDictionary *treeNodePosition;
@property (nonatomic, retain) NSString *fatherId;
@property (nonatomic, retain) NSString *strSelectedIndex;
@property (nonatomic, retain) NSMutableArray *treeNodesItemBack;
@end
